<?php

include_once('Logging.php');
include_once ('plugin/GaoDeAPIClass.php');
class SendSMSClass
{
    const t_send_sms = 'http://sms.shjieta.com.cn/';
    const send_sms = 'dx.ganso.com.cn/';
    /**
     * 发送信息
     * @param $send
     * @param $url
     * @return bool|string
     */
    function sendSMS($debug,$send){
        $url = (($debug) ? self::t_send_sms : self::send_sms).'service/api/smssend';
        $header_data[]  =  "Content-type:application/json";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header_data);
        curl_setopt($ch, CURLOPT_POST, true);
//        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($send));
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($send));
        $sResult = curl_exec($ch);
        if($sError=curl_error($ch)){
            die($sError);
        }
        curl_close($ch);
        return $sResult;
    }


    /**
     * 获取模板
     * @param $send
     * @param $url
     * @return bool|string
     */
    function getTemplateData($debug,$send){
        $url = (($debug) ? self::t_send_sms : self::send_sms).'service/api/smsinfo';
        $header_data[]  =  "Content-type:application/json";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header_data);
        curl_setopt($ch, CURLOPT_POST, true);
//        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($send));
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($send));
        $sResult = curl_exec($ch);
        if($sError=curl_error($ch)){
            die($sError);
        }
        curl_close($ch);
        return $sResult;
    }
}
